package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.ScenicSpots;
import com.ruoyi.camp.domain.WxScenicSpots;
import com.ruoyi.camp.service.IScenicSpotsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "营地周边景点管理", tags = {"营地周边景点管理"})
@RestController
@RequestMapping("/wechat/spots")
public class WxScenicSpotsController extends BaseController {

    @Autowired
    private IScenicSpotsService scenicSpotsService;

    @ApiOperation(value = "根据营地Id查询周边景点列表", response = WxScenicSpots.class)
    @GetMapping("/getInfoByCampId/{campId}")
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<ScenicSpots> list = scenicSpotsService.getInfoByCampId(campId);
        return success(list);
    }


    @ApiOperation(value = "添加周边景点并提交审批")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ScenicSpots scenicSpots){
        if (scenicSpots == null) {
            return error("数据不能为空");
        }
        if (scenicSpots.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (scenicSpots.getScenicName() == null) {
            return error("景点名称不能为空");
        }
        if (scenicSpots.getLatitude() == null || scenicSpots.getLongitude() == null) {
            return error("经纬度不能为空");
        }
        return toAjax(scenicSpotsService.insertScenicSpots(scenicSpots));
    }
    @DeleteMapping("/{scenicIds}")
    public AjaxResult remove(@PathVariable String[] scenicIds)
    {
        return toAjax(scenicSpotsService.deleteScenicSpotsByScenicIds(scenicIds));
    }
}
